import Vue from 'vue'
import Vuex from 'vuex'


Vue.use(Vuex)

/*
const state ={

  user:{

    userName:''

  }

};
const getters={

  getUser(state){

    return state.user;

  }

};
const mutations={

  updateUser(state,user){

    state.user = user;

  }

};
const actions={

  asyncUpdateUser(context,user){

    context.commit("updateUser",user);

  }

};
export default new Vuex.Store({

  state,

  getters,

  mutations,

  actions,

});
*/

const state = {
  userName: '' || localStorage.getItem('userName'),
  token:'',
  password:'',
  projectId: '1',
  rowId:''
};
const mutations = {

  handleUserName: (state, user_name) => {
    state.userName = user_name
    // 把登录的用户的名保存到localStorage中，防止页面刷新，导致vuex重新启动，用户名就成为初始值（初始值为空）的情况
    localStorage.setItem('userName', user_name)
  },
  setToken:(state,token)=>{
    state.token=token
    localStorage.setItem('token', token)
  },
  handlePassword:(state,password)=>{
    state.password = password
    localStorage.setItem('password',password)
  },
  SET_PROJECTID: (state, id) => {
    state.projectId = id
  },
  getRowId:(state,rowId)=>{
    state.rowId = rowId
    localStorage.setItem('getRowId',rowId)
  }

};
const actions= {
  saveId(id) {
  commit('SET_PROJECTID', id)
}
}
/*const getters = {
  userName: (state) => state.userName,
};*/
const store = new Vuex.Store({
  namespaced: true,
  state,

/*  getters,*/
  actions,
  mutations,

})
export default store

